package com.googlecode.horncomb.organ.srvc.support;

import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

import com.googlecode.horncomb.organ.Membership;
import com.googlecode.horncomb.organ.srvc.MembershipService;
import com.googlecode.horncomb.organ.srvc.RelationService;

/**
 * @author Daniel
 */
@SuppressWarnings("unchecked")
public class DefaultMembershipService implements MembershipService,
		InitializingBean {
	private RelationService relationService;

	/**
	 * {@inheritDoc}
	 */
	public void afterPropertiesSet() throws Exception {
		Assert.notNull(this.relationService);
	}

	/**
	 * {@inheritDoc}
	 */
	public void create(Membership membership) {
		this.relationService.create(membership);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<? extends Membership> findMemberships(
			Collection<String> groupIds, String personId,
			String[] membershipNatures) {
		return (List<Membership>) this.relationService.findRelations(groupIds,
				personId, membershipNatures);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<? extends Membership> findMemberships(String groupId,
			Collection<String> personIds, String[] membershipNatures) {
		return (List<Membership>) this.relationService.findRelations(groupId,
				personIds, membershipNatures);
	}

	/**
	 * {@inheritDoc}
	 */
	public List<? extends Membership> findMemberships(String groupId,
			String personId, String[] membershipNatures) {
		return (List<Membership>) this.relationService.findRelations(groupId,
				personId, membershipNatures);
	}

	/**
	 * {@inheritDoc}
	 */
	public Membership get(String groupId, String personId,
			String membershipNature) {
		return (Membership) this.relationService.get(groupId, personId,
				membershipNature);
	}

	/**
	 * {@inheritDoc}
	 */
	public Membership getById(String id) {
		return (Membership) this.relationService.getById(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeBetween(Collection<String> groupIds, String personId,
			String[] membershipNatures, boolean deleted) {
		this.relationService.removeBetween(groupIds, personId,
				membershipNatures, deleted);
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeBetween(String groupId, Collection<String> personIds,
			String[] membershipNatures, boolean deleted) {
		this.relationService.removeBetween(groupId, personIds,
				membershipNatures, deleted);
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeBetween(String groupId, String personId,
			String[] membershipNatures, boolean deleted) {
		this.relationService.removeBetween(groupId, personId,
				membershipNatures, deleted);
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeById(String membershipId, boolean deleted) {
		this.relationService.removeById(membershipId, deleted);
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeByIds(Collection<String> membershipIds, boolean deleted) {
		this.relationService.removeByIds(membershipIds, deleted);
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeInGroup(String groupId, String[] personNatures,
			String[] membershipNatures, boolean deleted) {
		this.relationService.removeFromSource(groupId, personNatures,
				membershipNatures, deleted);
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeInGroups(Collection<String> groupIds,
			String[] personNatures, String[] membershipNatures, boolean deleted) {
		this.relationService.removeToTargets(groupIds, personNatures,
				membershipNatures, deleted);
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeToPerson(String personId, String[] groupNatures,
			String[] membershipNatures, boolean deleted) {
		this.relationService.removeToTarget(personId, groupNatures,
				membershipNatures, deleted);
	}

	/**
	 * {@inheritDoc}
	 */
	public void removeToPersons(Collection<String> personIds,
			String[] groupNatures, String[] membershipNatures, boolean deleted) {
		this.relationService.removeToTargets(personIds, groupNatures,
				membershipNatures, deleted);
	}
}
